package xyz.jcat.webflux.sucurity;

import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import xyz.jcat.common.web.Resp;
import xyz.jcat.common.web.RespCodeMsg;

/**
 * 权限异常处理
 */
public class DefaultServerAccessDeniedHandler implements ServerAccessDeniedHandler {

    @Override
    public Mono<Void> handle(ServerWebExchange serverWebExchange, AccessDeniedException e) {
        return ServerUtils.writeJson(serverWebExchange, HttpStatus.FORBIDDEN, Resp.fail(RespCodeMsg.FORBIDDEN));
    }
}
